//
//  CHHLoadingView.m
//  小宝爱学
//
//  Created by imac on 15/9/9.
//  Copyright (c) 2015年 imac. All rights reserved.
//

#import "BaseView.h"
#import "CHHLoadingView.h"
#import "PopUpView.h"
#import "CustomDefine.h"
#import "SXLoadingView.h"

UIWindow *mainWindow() {
    id appDelegate = [UIApplication sharedApplication].delegate;
    if (appDelegate && [appDelegate respondsToSelector:@selector(window)]) {
        return [appDelegate window];
    }
    
    NSArray *windows = [UIApplication sharedApplication].windows;
    if ([windows count] == 1) {
        return [windows firstObject];
    }
    else {
        for (UIWindow *window in windows) {
            if (window.windowLevel == UIWindowLevelNormal) {
                return window;
            }
        }
    }
    return nil;
}
//static PopUpView *s_popUpView=nil;
static BaseView *_loadingView=nil;
@implementation CHHLoadingView
+ (void)showAlertLV:(NSString *)aString duration:(CGFloat)duration{
    [SXLoadingView hideProgressHUD];
    PopUpView *popUpView=[[PopUpView alloc]initWithtext:aString andView:mainWindow()];
    [mainWindow() addSubview:popUpView];
    [popUpView hiddenByDuration:duration];
}

+ (void)showProgressLoadingView:(NSString *)aString{
    BaseView *loadingView=[[BaseView alloc]initWithFrame:CGRectMake(__kWidth/2-50, __kHeight/2-50, 100, 100)];
    [mainWindow() addSubview:loadingView];
    _loadingView=loadingView;
    
    UIImageView *loadingIV=[[UIImageView alloc]initWithFrame:loadingView.bounds];
    loadingIV.backgroundColor=[UIColor redColor];
    [loadingView addSubview:loadingIV];
}
+(void)hideProgrssLoadingeView{
    if (_loadingView) {
        [_loadingView removeFromSuperview];
    }
}
@end
